#include <iostream>
using namespace std;
char * mysort_chars(char *src_str, const char *rule)
{
	int char_flag[256]={0};
	char *str_temp=src_str;
	int len_rule=strlen(rule);
	while(*str_temp!='\0')
	{
		char_flag[*(str_temp++)]++;
	}
	for (int i=0,j=0;i<len_rule;i++)
	{
		while(char_flag[rule[i]]-->0)
		{
			src_str[j++]=rule[i];
		}
	}
	return src_str;
}

int main()
{
		char array[]="abc";
		const char *rule = "cfadbe";
		mysort_chars(array,rule);
		cout<<array<<endl;
}